package com.hkd.blogsystem.mapper;

import com.hkd.blogsystem.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BlogInfoMapper {
    /**
     * 查询所有博客
     */
    @Select("SELECT id, title, SUBSTRING(content, 1, 175) AS content, user_id, update_time FROM blog WHERE delete_flag = 0 ORDER BY id DESC")
    List<BlogInfo> selectAll();
    /**
     *根据博客Id,查询博客信息
     */
    @Select("select id,title,content,user_id,update_time from blog where id = #{id} and delete_flag = 0")
    BlogInfo selectById(Integer id);
    /**
     * 插入博客
     */
    @Insert("insert into blog (title,content,user_id) values (#{title},#{content},#{userId})")
    Integer insertBlog(BlogInfo blogInfo);
    /**
     * 更新博客
     */

    Integer updateBlog(BlogInfo blogInfo);
}
